package  
{
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Spritemap;
	import net.flashpunk.FP;
	/**
	 * © 2012 TheJavaArcade.com
	 */	
	public class Bee extends Entity {
		private var beeSprite:Spritemap = new Spritemap(Assets.BEE_SPRITE, 16, 16);
		public var level:int;
		public var state:int;
		
		public function Bee(theLevel:int) {
			level = theLevel;
			state = 0;
			beeSprite.add("fly", [0,1,2,1], 20, true);
			graphic = beeSprite;
			beeSprite.play("fly");
			type = "bee";
			setHitbox(48, 48, 16, 16);
			layer = 1;
			var dataList:XMLList;
			var dataElement:XML;
			dataList = GameEngine.levelXML[theLevel].bugs.bee;
			for each(dataElement in dataList) {
				x = dataElement.@x;
				y = dataElement.@y;
			}
		}
		override public function update():void {
			if (GameEngine.level == level && collide("fracas", x , y)) {
				if (GameEngine.hive.state == 1) state = 1;
				if (state == 0) {
					GameEngine.beeDialogue.theText.text = "I'm a bee without a HIVE...\nmy life is so empty.";
					GameEngine.beeDialogue.y = y - 25;
				}
				if (state == 1) {
					GameEngine.beeDialogue.theText.align = "left";
					GameEngine.beeDialogue.theText.text = "   You found my HIVE!\n I'm so f*@&ing happy :)\nplease have this reward.";
					GameEngine.beeDialogue.y = y - 38;
					GameEngine.heart.visible = true;
					GameEngine.heart.state = 1;
				}
				if (state == 2) {
					GameEngine.beeDialogue.theText.text = "Thank you for finding my HIVE.";
					GameEngine.beeDialogue.y = y - 25;
				}
				GameEngine.beeDialogue.x = (x +8) - (GameEngine.beeDialogue.theText.width / 2);
				GameEngine.beeDialogue.visible = true;
			}else {
				GameEngine.beeDialogue.visible = false
				if (state == 1) {
					state = 2;
					GameEngine.hive.state = 3;
				}
			}
		}		
	}

}